package com.albaba.designpattern.memento.text_002;

/**
 * @Description: TODO
 * @Author zx
 * @Date 2025/2/27 16:13
 * @Version 1.0
 */
public class MainApp {

    public static void main(String[] args) throws InterruptedException {
        // 创建玩家类，设置初始金币
        Player player = new Player(100);
        // 创建备忘录对象
        Memento memento = player.createMemento();

        for (int i = 0; i < 100; i++) {
            System.out.println("======================================");
            // 显示扔骰子的次数
            System.out.println("第" + (i + 1) + "次骰子");
            // 显示当前玩家状态
            System.out.println("当前玩家状态：" + player);
            // 开启游戏
            player.yacht();
            System.out.println("玩家所持有的金币：" + player.getMoney() + "元");
            // 复活操作
            if (player.getMoney() > memento.getMoney()) {
                System.out.println("赚到金币，保存当前状态，继续游戏!");
                memento = player.createMemento();
            } else if (player.getMoney() < memento.getMoney() / 2) {
                System.out.println("所持游戏不多了，将游戏恢复到初始状态");
                player.restoreMemento(memento);
            }
            Thread.sleep(5000);
            System.out.println("======================================");
        }
    }

}
